package com.core.model.user;

import com.core.dto.ForEnumDTO;
import org.apache.commons.collections.map.HashedMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: ZhongGang
 * Date: 15-1-7
 * Time: 下午10:41
 */
public enum Privilege {

    USER_MANAGEMENT("用户管理"),

    DEPARTMENT_MANAGEMENT("部门管理"),

    ROLE_MANAGEMENT("角色管理"),

    XG_MANAGEMENT("兴国制冷管理");

    private String label;

    private Privilege(String label) {
        this.label = label;
    }

    public String getLabel() {
        return label;
    }

    public String getValue() {
        return name();
    }

    public String getGrantedAuthority() {
        return name();
    }

    public static List<ForEnumDTO> toDTO() {
        List<ForEnumDTO> forEnumDTOs = new ArrayList<>();
        for (Privilege privilege : Privilege.values()) {
            String value = privilege.name();
            String label = privilege.getLabel();
            ForEnumDTO forEnumDTO = new ForEnumDTO(value, label);
            forEnumDTOs.add(forEnumDTO);
        }
        return forEnumDTOs;
    }

    public static Map<String, Object> toMap() {
        Map<String, Object> map = new HashedMap();
        for (Privilege privilege : Privilege.values()) {
            map.put(privilege.name(), privilege.getLabel());
        }
        return map;
    }

    public static List<String> toNames() {
        List<String> list = new ArrayList<>();
        for (Privilege privilege : Privilege.values()) {
            list.add(privilege.name());
        }
        return list;
    }

    public static List<String> toLabels() {
        List<String> list = new ArrayList<>();
        for (Privilege privilege : Privilege.values()) {
            list.add(privilege.getLabel());
        }
        return list;
    }
}
